#include "Histogram3D.h"
#include "common.h"

#include "img/pixAdjust.xpm"
#include "img/pixMesh.xpm"
#include "img/pixSurf.xpm"
#include "img/pixBars.xpm"

//-------------------------------------

Histogram3D::Histogram3D( QVector< double > & data, int _rows, int _columns, QWidget * parent ) :
    QFrame( parent )
{
    resize( 500, 500 );
    setWindowTitle( "3D Histogram" );

    surf = new MainPlot3D( this );
    surf->Init( data, _rows, _columns );

    surf->UseBars( true );

    grLay = new QGridLayout( this );
    grLay->setContentsMargins( 1, 1, 1, 1 );
    grLay->addWidget( surf->Wgt(), 0, 0 );

    toolPalette = new QToolBar();
    toolPalette->setParent( this );
    grLay->setMenuBar( toolPalette );
    toolPalette->addAction( QPixmap( pixBars_xpm ), str8bit( TCHART_BARS_VIEW ) );
    toolPalette->addAction( QPixmap( pixAdjust_xpm ), str8bit( TCHART_3D_NORM_VIEW ) );
    toolPalette->addAction( QPixmap( pixMesh_xpm ), str8bit( TCHART_3D_MESH_VISIBILITY ) );
    connect( toolPalette, SIGNAL( actionTriggered(QAction*) ), this, SLOT( sltToolPaletteClick(QAction*) ) );
}

//-------------------------------------

void Histogram3D::sltToolPaletteClick( QAction * a )
{
    if( a->text() == TCHART_3D_NORM_VIEW )
    {
        surf->Reset();
    }
    else if( a->text() == TCHART_BARS_VIEW )
    {
        surf->UseBars( !surf->UseBars() );
    }
    else if( a->text() == TCHART_3D_MESH_VISIBILITY )
    {
        if( surf->UseBars() )
        {
            surf->ShowBarBorder( !surf->ShowBarBorder() );
        }
        else
        {
            Qwt3D::RGBA rgba = surf->MeshColor();
            rgba.a = !rgba.a;
            surf->SetMeshColor( rgba );
        }
    }
}

//-------------------------------------
